using System;
using System.Collections.Generic;
using System.Text;
using GameEditor.Common;

namespace TaskSystemClient
{
    sealed class StringListSerializer
    {
        private StringListSerializer()
        {
        }
        public static string[] SplitByParenthese(string s)
        {
            if (string.IsNullOrEmpty(s))
                return new string[0];
            s = s.Substring(1, s.Length - 2).Replace("(", "");
            return s.Split(')');
        }
        public static string[] SplitByComma(string s)
        {
            List<String> ret = new List<string>();
            if (!string.IsNullOrEmpty(s))
            {
                foreach (string str in s.Split(','))
                {
                    if (!string.IsNullOrEmpty(str.Trim()))
                        ret.Add(str.Trim());
                }
            }
            return ret.ToArray();
        }
        public static string SeparatedByComma(string[] s)
        {
        
            if (s == null || s.Length == 0)
                return string.Empty;
            StringBuilder sb = new StringBuilder();
            foreach (string str in s)
            {
                if (string.IsNullOrEmpty(str))
                    continue;
                if (sb.Length > 0)
                    sb.Append(",");
                sb.AppendFormat("{0}", str);
            }
            return sb.ToString();
        }
        public static string QuotedByParenthese(string[] s)
        {
            if (s == null || s.Length == 0)
                return string.Empty;
            StringBuilder sb = new StringBuilder();
            foreach (string str in s)
            {
                if (string.IsNullOrEmpty(str))
                    continue;
                if (sb.Length > 0)
                    sb.Append(",");
                sb.AppendFormat("({0})", str);
            }
            return sb.ToString();
        }
    }
}
